{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyautogui\n",
    "import time\n",
    "import xlrd\n",
    "import pyperclip\n",
    "import pandas as pd\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#定义鼠标事件\n",
    "# 鼠标操作\n",
    "#pyautogui库其他用法 https://blog.csdn.net/qingfengxd1/article/details/108270159\n",
    "# clickTimes 点击次数 \n",
    "# lOrR 鼠标左键还是右键 \n",
    "# img 图片地址 \n",
    "# reTry 重试 \n",
    "def mouseClick(clickTimes,lOrR,img,reTry):\n",
    "    if reTry == 1:\n",
    "        while True:\n",
    "            time.sleep(1)\n",
    "            try:\n",
    "                location=pyautogui.locateCenterOnScreen(img,confidence=0.9)\n",
    "            except Exception as e:\n",
    "                time.sleep(1)\n",
    "                continue\n",
    "            if location is not None:\n",
    "                pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)\n",
    "                break\n",
    "            print(\"未找到匹配图片,0.1秒后重试\")\n",
    "            time.sleep(0.1)\n",
    "    elif reTry == -1:\n",
    "        while True:\n",
    "            time.sleep(1)\n",
    "            location=pyautogui.locateCenterOnScreen(img,confidence=0.9)\n",
    "            if location is not None:\n",
    "                pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)\n",
    "            time.sleep(0.1)\n",
    "    elif reTry > 1:\n",
    "        i = 1\n",
    "        while i < reTry + 1:\n",
    "            time.sleep(1)\n",
    "            location=pyautogui.locateCenterOnScreen(img,confidence=0.9)\n",
    "            if location is not None:\n",
    "                pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)\n",
    "                print(\"重复\")\n",
    "                i += 1\n",
    "            time.sleep(0.1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据检查\n",
    "# cmdType.value  1.0 左键单击    2.0 左键双击  3.0 右键单击  4.0 输入  5.0 等待  6.0 滚轮\n",
    "# ctype     空：0\n",
    "#           字符串：1\n",
    "#           数字：2\n",
    "#           日期：3\n",
    "#           布尔：4\n",
    "#           error：5\n",
    "def dataCheck(sheet1):\n",
    "    checkCmd = True\n",
    "    #行数检查\n",
    "    if sheet1.nrows<2:\n",
    "        print(\"没数据啊哥\")\n",
    "        checkCmd = False\n",
    "    #每行数据检查\n",
    "    i = 1\n",
    "    while i < sheet1.nrows:\n",
    "        # 第1列 操作类型检查\n",
    "        cmdType = sheet1.row(i)[0]\n",
    "        if cmdType.ctype != 2 or (cmdType.value != 1.0 and cmdType.value != 2.0 and cmdType.value != 3.0 \n",
    "        and cmdType.value != 4.0 and cmdType.value != 5.0 and cmdType.value != 6.0 and cmdType.value != 7.0\n",
    "        and cmdType.value != 8.0 and cmdType.value != 9.0):\n",
    "            print('第',i+1,\"行,第1列数据有毛病\")\n",
    "            checkCmd = False\n",
    "        # 第2列 内容检查\n",
    "        cmdValue = sheet1.row(i)[1]\n",
    "        # 读图点击类型指令，内容必须为字符串类型\n",
    "        if cmdType.value ==1.0 or cmdType.value == 2.0 or cmdType.value == 3.0:\n",
    "            if cmdValue.ctype != 1:\n",
    "                print('第',i+1,\"行,第2列数据有毛病\")\n",
    "                checkCmd = False\n",
    "        # 输入类型，内容不能为空\n",
    "        if cmdType.value == 4.0:\n",
    "            if cmdValue.ctype == 0:\n",
    "                print('第',i+1,\"行,第2列数据有毛病\")\n",
    "                checkCmd = False\n",
    "        # 等待类型，内容必须为数字\n",
    "        if cmdType.value == 5.0:\n",
    "            if cmdValue.ctype != 2:\n",
    "                print('第',i+1,\"行,第2列数据有毛病\")\n",
    "                checkCmd = False\n",
    "        # 滚轮事件，内容必须为数字\n",
    "        if cmdType.value == 6.0:\n",
    "            if cmdValue.ctype != 2:\n",
    "                print('第',i+1,\"行,第2列数据有毛病\")\n",
    "                checkCmd = False\n",
    "        \n",
    "        i += 1\n",
    "    return checkCmd\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#任务\n",
    "def mainWork(sheet1,path_dev,mission_times=1):\n",
    "    i = 1\n",
    "    while i < sheet1.nrows:\n",
    "        #取本行指令的操作类型\n",
    "        cmdType = sheet1.row(i)[0]\n",
    "        if cmdType.value == 1.0:\n",
    "            #取图片名称\n",
    "            img = sheet1.row(i)[1].value\n",
    "            img = path_dev+img\n",
    "            print(img)\n",
    "            reTry = 1\n",
    "            if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:\n",
    "                reTry = sheet1.row(i)[2].value\n",
    "            mouseClick(1,\"left\",img,reTry)\n",
    "            print(\"单击左键\",img)\n",
    "        #2代表双击左键\n",
    "        elif cmdType.value == 2.0:\n",
    "            #取图片名称\n",
    "            img = sheet1.row(i)[1].value\n",
    "            img = path_dev+img\n",
    "            #取重试次数\n",
    "            reTry = 1\n",
    "            if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:\n",
    "                reTry = sheet1.row(i)[2].value\n",
    "            mouseClick(2,\"left\",img,reTry)\n",
    "            print(\"双击左键\",img)\n",
    "        #3代表右键\n",
    "        elif cmdType.value == 3.0:\n",
    "            #取图片名称\n",
    "            img = sheet1.row(i)[1].value\n",
    "            img = path_dev+img\n",
    "            #取重试次数\n",
    "            reTry = 1\n",
    "            if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:\n",
    "                reTry = sheet1.row(i)[2].value\n",
    "            mouseClick(1,\"right\",img,reTry)\n",
    "            print(\"右键\",img) \n",
    "        #4代表输入\n",
    "        elif cmdType.value == 4.0:\n",
    "            inputValue = sheet1.row(i)[1].value\n",
    "            pyperclip.copy(inputValue)\n",
    "            pyautogui.hotkey('ctrl','v')\n",
    "            time.sleep(0.5)\n",
    "            print(\"输入:\",inputValue)                                        \n",
    "        #5代表等待\n",
    "        elif cmdType.value == 5.0:\n",
    "            #取图片名称\n",
    "            waitTime = sheet1.row(i)[1].value\n",
    "            time.sleep(waitTime)\n",
    "            print(\"等待\",waitTime,\"秒\")\n",
    "        #6代表滚轮\n",
    "        elif cmdType.value == 6.0:\n",
    "            #取图片名称\n",
    "            scroll = sheet1.row(i)[1].value\n",
    "            pyautogui.scroll(int(scroll))\n",
    "            print(\"滚轮滑动\",int(scroll),\"距离\")\n",
    "        # 7 代表删除,第二列的值表示删除几个字符\n",
    "        elif cmdType.value == 7.0:\n",
    "            delete_times = sheet1.row(i)[1].value\n",
    "            if delete_times == '':\n",
    "                delete_times=1\n",
    "            else:\n",
    "                pass\n",
    "            print(delete_times)\n",
    " \n",
    "            for j in range(int(delete_times)):\n",
    "                pyautogui.press('backspace')\n",
    "                print(\"删除了一个字符，这是第 \", j+1 ,\"次删除\")\n",
    "        # 8 根据另外的表格某一列数据进行输入\n",
    "        elif cmdType.value == 8.0:\n",
    "            # 外部数据\n",
    "            # 需要 csv 文件名称和对应列数，从 1 开始计数,用逗号分割,文件名英语命名不含逗号             \n",
    "            inputValue = sheet1.row(i)[1].value\n",
    "            list_input = inputValue.split(',')\n",
    "            path = path_dev+list_input[0]\n",
    "            wbb = xlrd.open_workbook(path)\n",
    "            extern_data = wbb.sheet_by_index(0)\n",
    "            inputValue_real =  extern_data.row(mission_times)[int(list_input[1])-1].value\n",
    "\n",
    "            pyperclip.copy(inputValue_real)\n",
    "            pyautogui.hotkey('ctrl','v')\n",
    "            time.sleep(0.5)\n",
    "            print(\"输入:\",inputValue)  \n",
    "        # 9 代表 tab,第二列的值表示 tab 几次\n",
    "        elif cmdType.value == 9.0:\n",
    "            tab_times = sheet1.row(i)[1].value\n",
    "            if tab_times == '':\n",
    "                tab_times=1\n",
    "            else:\n",
    "                pass\n",
    "            print(tab_times)\n",
    " \n",
    "            for j in range(int(tab_times)):\n",
    "                pyautogui.press('tab')\n",
    "                print(\"增加一个 tab 字符，这是第 \", j+1 ,\"个 tab\")          \n",
    "                \n",
    "        i += 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用不高兴就喝水牌RPA~\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "选择功能: 1.做一次 2.给定次数 \n",
      " 2\n",
      "输入次数 \n",
      " 100\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<module 'time' (built-in)>\n",
      "./dev_pic/1.png\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'exception' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImageNotFoundException\u001b[0m                    Traceback (most recent call last)",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyautogui\\__init__.py:172\u001b[0m, in \u001b[0;36mraisePyAutoGUIImageNotFoundException.<locals>.wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    171\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 172\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m wrappedFunction(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m    173\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m pyscreeze\u001b[38;5;241m.\u001b[39mImageNotFoundException:\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyautogui\\__init__.py:204\u001b[0m, in \u001b[0;36mlocateCenterOnScreen\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    202\u001b[0m \u001b[38;5;129m@raisePyAutoGUIImageNotFoundException\u001b[39m\n\u001b[0;32m    203\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlocateCenterOnScreen\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m--> 204\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m pyscreeze\u001b[38;5;241m.\u001b[39mlocateCenterOnScreen(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyscreeze\\__init__.py:447\u001b[0m, in \u001b[0;36mlocateCenterOnScreen\u001b[1;34m(image, **kwargs)\u001b[0m\n\u001b[0;32m    444\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    445\u001b[0m \u001b[38;5;124;03mTODO\u001b[39;00m\n\u001b[0;32m    446\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m--> 447\u001b[0m coords \u001b[38;5;241m=\u001b[39m locateOnScreen(image, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m    448\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m coords \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyscreeze\\__init__.py:405\u001b[0m, in \u001b[0;36mlocateOnScreen\u001b[1;34m(image, minSearchTime, **kwargs)\u001b[0m\n\u001b[0;32m    404\u001b[0m screenshotIm \u001b[38;5;241m=\u001b[39m screenshot(region\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m--> 405\u001b[0m retVal \u001b[38;5;241m=\u001b[39m locate(image, screenshotIm, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m    406\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyscreeze\\__init__.py:383\u001b[0m, in \u001b[0;36mlocate\u001b[1;34m(needleImage, haystackImage, **kwargs)\u001b[0m\n\u001b[0;32m    382\u001b[0m kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlimit\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m--> 383\u001b[0m points \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mtuple\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mlocateAll\u001b[49m\u001b[43m(\u001b[49m\u001b[43mneedleImage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhaystackImage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    384\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(points) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyscreeze\\__init__.py:257\u001b[0m, in \u001b[0;36m_locateAll_opencv\u001b[1;34m(needleImage, haystackImage, grayscale, limit, region, step, confidence)\u001b[0m\n\u001b[0;32m    256\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m USE_IMAGE_NOT_FOUND_EXCEPTION:\n\u001b[1;32m--> 257\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m ImageNotFoundException(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCould not locate the image (highest confidence = \u001b[39m\u001b[38;5;132;01m%.3f\u001b[39;00m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m result\u001b[38;5;241m.\u001b[39mmax())\n\u001b[0;32m    258\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "\u001b[1;31mImageNotFoundException\u001b[0m: Could not locate the image (highest confidence = 0.411)",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mImageNotFoundException\u001b[0m                    Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 13\u001b[0m, in \u001b[0;36mmouseClick\u001b[1;34m(clickTimes, lOrR, img, reTry)\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m---> 13\u001b[0m     location\u001b[38;5;241m=\u001b[39m\u001b[43mpyautogui\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlocateCenterOnScreen\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimg\u001b[49m\u001b[43m,\u001b[49m\u001b[43mconfidence\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.9\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m     14\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m exception \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32m~\\miniconda3\\lib\\site-packages\\pyautogui\\__init__.py:174\u001b[0m, in \u001b[0;36mraisePyAutoGUIImageNotFoundException.<locals>.wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    173\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m pyscreeze\u001b[38;5;241m.\u001b[39mImageNotFoundException:\n\u001b[1;32m--> 174\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m ImageNotFoundException\n",
      "\u001b[1;31mImageNotFoundException\u001b[0m: ",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[5], line 20\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mint\u001b[39m(times)):\n\u001b[0;32m     19\u001b[0m     \u001b[38;5;28mprint\u001b[39m(time)\n\u001b[1;32m---> 20\u001b[0m     \u001b[43mmainWork\u001b[49m\u001b[43m(\u001b[49m\u001b[43msheet1\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfile_dir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mi\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m     21\u001b[0m     time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m10\u001b[39m)\n",
      "Cell \u001b[1;32mIn[4], line 15\u001b[0m, in \u001b[0;36mmainWork\u001b[1;34m(sheet1, path_dev, mission_times)\u001b[0m\n\u001b[0;32m     13\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m sheet1\u001b[38;5;241m.\u001b[39mrow(i)[\u001b[38;5;241m2\u001b[39m]\u001b[38;5;241m.\u001b[39mctype \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m sheet1\u001b[38;5;241m.\u001b[39mrow(i)[\u001b[38;5;241m2\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m     14\u001b[0m         reTry \u001b[38;5;241m=\u001b[39m sheet1\u001b[38;5;241m.\u001b[39mrow(i)[\u001b[38;5;241m2\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue\n\u001b[1;32m---> 15\u001b[0m     \u001b[43mmouseClick\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mleft\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43mimg\u001b[49m\u001b[43m,\u001b[49m\u001b[43mreTry\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     16\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m单击左键\u001b[39m\u001b[38;5;124m\"\u001b[39m,img)\n\u001b[0;32m     17\u001b[0m \u001b[38;5;66;03m#2代表双击左键\u001b[39;00m\n",
      "Cell \u001b[1;32mIn[2], line 14\u001b[0m, in \u001b[0;36mmouseClick\u001b[1;34m(clickTimes, lOrR, img, reTry)\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m     13\u001b[0m     location\u001b[38;5;241m=\u001b[39mpyautogui\u001b[38;5;241m.\u001b[39mlocateCenterOnScreen(img,confidence\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.9\u001b[39m)\n\u001b[1;32m---> 14\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[43mexception\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m     15\u001b[0m     time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m     16\u001b[0m     \u001b[38;5;28;01mcontinue\u001b[39;00m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'exception' is not defined"
     ]
    }
   ],
   "source": [
    "file = 'cmd.xls'\n",
    "file_dir = \"./dev_pic/\"\n",
    "# file_dir = \"./\"\n",
    "#打开文件\n",
    "wb = xlrd.open_workbook(filename=file)\n",
    "#通过索引获取表格sheet页\n",
    "sheet1 = wb.sheet_by_index(0)\n",
    "print('欢迎使用不高兴就喝水牌RPA~')\n",
    "# 数据检查\n",
    "checkCmd = dataCheck(sheet1)\n",
    "if checkCmd:\n",
    "    key=input('选择功能: 1.做一次 2.给定次数 \\n')\n",
    "    if key=='1':\n",
    "        #循环拿出每一行指令\n",
    "        mainWork(sheet1, file_dir)\n",
    "    if key=='2':\n",
    "        times = input('输入次数 \\n')\n",
    "        for i in range(int(times)):\n",
    "            print(time)\n",
    "            mainWork(sheet1, file_dir, i+1)\n",
    "            time.sleep(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = r\"C:\\Users\\cwj\\Desktop\\jwlauto\\dev_pic\\1.png\"\n",
    "location=pyautogui.locateCenterOnScreen(img,confidence=0.9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
